#ifndef STRATUM_COIND_H
#define STRATUM_COIND_H
#include <pthread.h>
#include "object.h"

class StratumCoind;

class StratumCoindAux {
public:
    StratumCoind* m_coind;

    int m_index;
    int m_chain_id;

    char m_hash[1024];
    char m_target[1024];
};

class StratumCoind: public StratumObject {
public:
    bool m_touch;
    bool m_new_coind;

    StratumRpc m_rpc;
    char m_rpc_encoding[32];

    pthread_mutex_t m_mutex;

    char m_name[1024];
    char m_symbol[256];
    char m_symbol2[256];
    char m_algo[256];
    char m_wallet[1024];
    char m_account[256];

    char m_pubkey[1024];
    char m_script_key[1024];
    bool m_p2sh_address;

    bool m_pos;
    bool m_has_submit_block;
    bool m_tx_message;

    char m_charity_address[1024];
    double m_charity_amount;
    double m_charity_percent;

    bool m_enable;
    bool m_auto_ready;
    bool m_new_block;
    char m_last_notify_hash[192];

    int m_height;
    double m_diff;

    double m_reward;
    double m_reward_mul;

    double m_price;
    int m_pool_ttf;
    int m_actual_ttf;

    bool m_is_aux;
    StratumCoindAux m_aux;

    int m_not_reporting_counter;
    bool m_use_get_work;
    bool m_use_memory_pool;
    bool m_has_master_nodes;
    bool m_old_master_nodes;
    bool m_multi_algos;

    bool m_use_sgewit;
    char m_commitment[128];
    char m_witness_magic[16];

    StratumJob* m_job;
};

inline void coindDel(StratumObject* obj) {
    StratumCoind* coind = (StratumCoind*)obj;
    objectDelete(coind->m_job);
    delete coind;
}


void coindError(StratumCoind* coind, const char* s);

double coindProfitability(StratumCoind* coind);
double coindNetHash(StratumCoind* coind);

bool coindCanMine(StratumCoind* coind, bool isaux=false);
void coindSort();


bool coindSubmit(StratumCoind* coind, const char* block);
bool coindSubmitGetAuxBlock(StratumCoind* coind, const char* hash, const char* block);

void coinInit(StratumCoind* coind);
void coindTerminate(StratumCoind* coind);

bool coindCreateJob(StratumCoind* coind, bool force=false);
bool coindValidateUserAddress(StratumCoind* coind, const char* address);

#endif //STRATUM_COIND_H
